<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>
    // es6的类 get 和set属性  
    //get 设置只读属性
    class Car {
      constructor(name, color) {
        this.name = name;
        this.color = color;
        this.price = 80;
      }
      get active_pirce() {  //active_pirce 是用get设置的属性  唯一属性 只读属性
        return this.price
      }
      set s_price(val) {//s_price用来设置price属性的值，从而改变active_price
        // val--接受到的值
        if (val > 170) {
          this.price = val + 20
        } else {
          this.price = val + 80
        }
      }
      run() { }
    }
    var pala = new Car("帕拉梅拉", "红色");
    console.log(pala.active_pirce)
    pala.s_price = 180;
    console.log(pala.active_pirce)










  </script>
</body>

</html>